﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Formboard.Resources;
using Formboard.Request;

namespace Formboard
{
    public partial class Menu : UserControl
    {

        public List<Board> boardList;
        public List<User> userList;

        public Menu()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void Menu_Load(object sender, EventArgs e)
        {
            boardList = ((Form1)this.Parent).requester.getBoards();  
            for (int i = 0; i < boardList.Count(); i++)
            {
                listBoxBoards.Items.Add(boardList[i].name+" - "+boardList[i].status);
            }

            userList = ((Form1)this.Parent).requester.getUsers();
            for (int i = 0; i < userList.Count(); i++)
            {
                listBoxPlayers.Items.Add(userList[i].screenname);
            }
        }

        private void buttonSignout_Click(object sender, EventArgs e)
        {
            ((Form1)this.Parent).goto_login_from_gamelauncher();
        }

        private void buttonCreateBoard_Click(object sender, EventArgs e)
        {
            DateTime today = new DateTime();
            today = DateTime.Now;
            String stringtoday = today.GetHashCode().ToString();
            String boardname = ((Form1)this.Parent).myscreenname + stringtoday;
            Board newboard = new Board(boardname, ((Form1)this.Parent).myscreenname);
            if (radioButtonBlack.Checked)
            {
                newboard.owner_white = false;
            }
            else
            {
                newboard.owner_white = true;
            }
            ((Form1)this.Parent).requester.createBoard(newboard);
            ((Form1)this.Parent).goto_board(newboard);
        }

        private void buttonJoinBoard_Click(object sender, EventArgs e)
        {
            int indexboardtojoin = listBoxBoards.SelectedIndex;
            ((Form1)this.Parent).requester.loadAllTheBoard(boardList[indexboardtojoin]);
            ((Form1)this.Parent).goto_board(boardList[indexboardtojoin]);
        }

        private void listBoxBoards_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void buttonRequest_Click(object sender, EventArgs e)
        {
            int indexboardtojoin = listBoxBoards.SelectedIndex;
            ((Form1)this.Parent).requester.askPermissionToJoin(new User(),boardList[indexboardtojoin]);
            ((Form1)this.Parent).requester.loadAllTheBoard(boardList[indexboardtojoin]);
            ((Form1)this.Parent).goto_board(boardList[indexboardtojoin]);

        }
    
    }
}
